/*******************************************************************************
 * 
 * Copyright:
 * 
 * License:
 * 
 * Authors: SALMON Charles
 * 
 ******************************************************************************/

/*******************************************************************************
 * 
 ******************************************************************************/
 
/**
 * Page model description
 * A page contains: the page content (page), the portlet, the services
 */
qx.Class.define("bip.PageModel",
{
  extend : qx.core.Object,

  /*
   *****************************************************************************
      CONSTRUCTOR
   *****************************************************************************
   */
  construct : function(props)
  {
    this.base(arguments);
    if (props != null) {this.set(props);}
  },
  
  /*
   *****************************************************************************
      PROPERTIES
   *****************************************************************************
   */
   properties :
   {
     pageClass:
     {
    	 check:"Class",
    	 nullable: false,
    	 init:bip.views.Page
     },
     
     portletClass:
     {
    	 check:"Class",
    	 nullable: false,
    	 init:bip.views.Portlet
     },
     
     portletWidth:
     {
    	 check:"Integer",
    	 nullable: false,
    	 init:260
     }
   
   },

   /*
   *****************************************************************************
      MEMBERS
   *****************************************************************************
   */

   members :
	 {
  	 __page: null,
  	 __portlet: null,
 
  	 /**
  	  * Return the page content
  	  * If the page instance is not yet created, create it
  	  * @return {bip.views.page} The page instance
  	  */
  	 getPage: function() {
  		 if (this.__page == null) {
  			 	var clazz = this.getPageClass();
  			 	this.__page = new clazz(this);
	       	// Register win
	        bip.Application.getPagesDesktop().add(this.__page);
	        this.__page.close();
  		 }
  		 return this.__page;
  	 },
  	 
  	 /**
  	  * Return the contextual portlet associated to the page 
  	  * If the portlet instance is not yet created, create it
  	  * @return {bip.views.Portlet} The portlet instance
  	  */
  	 getPortlet: function() {
  		 if (this.__portlet == null) {
  			 	var clazz = this.getPortletClass();
  			 	this.__portlet = new clazz(this);
	       	// Register win
	       	bip.Application.getPortletsDesktop().add(this.__portlet);
	       	this.__portlet.close();
  		 }
  		 return this.__portlet;
  	 }
	 
	 
	 },



  /*
   *****************************************************************************
      DESTRUCTOR
   *****************************************************************************
   */

  destruct : function() {
  	this.disposeObject("__page","__portlet");
  }
});
